package com.xkstream.client.ui.adapter;

import android.content.Context;
import android.graphics.Typeface;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.xkstream.client.R;
import com.xkstream.client.entity.ReceiveGift;

import java.util.List;

/**
 * Created by admin on 2017/4/11.
 */

public class GiftContributionAdapter extends BaseAdapter {
    List<ReceiveGift> list;
    Context context;

    public GiftContributionAdapter(List<ReceiveGift> list, Context context) {
        this.list = list;
        this.context = context;
    }

    @Override
    public int getCount() {
        return list.size();
    }

    @Override
    public Object getItem(int position) {
        return list.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder holder = null;
        if(convertView == null){
            holder = new ViewHolder();
            convertView = View.inflate(context, R.layout.layout_giftcontribution_item,null);
            holder.ivContribution = (ImageView)convertView.findViewById(R.id.ivContribution);
            holder.tvName = (TextView)convertView.findViewById(R.id.tvName);
            holder.tvRankNum = (TextView)convertView.findViewById(R.id.tvRankNum);
            convertView.setTag(holder);
        }else{
            holder = (ViewHolder)convertView.getTag();
        }
        ReceiveGift receiveGift = list.get(position);
        if(position == 0){
            holder.ivContribution.setVisibility(View.VISIBLE);
            holder.ivContribution.setImageDrawable(context.getResources().getDrawable(R.drawable.contribution_first));
            holder.tvName.setTextColor(context.getResources().getColor(R.color.violet_ff41ba));
            holder.tvRankNum.setTextColor(context.getResources().getColor(R.color.violet_ff41ba));
            holder.tvRankNum.setTypeface(Typeface.defaultFromStyle(Typeface.BOLD));
            holder.tvName.setTypeface(Typeface.defaultFromStyle(Typeface.BOLD));
        }else if(position == 1){
            holder.ivContribution.setVisibility(View.VISIBLE);
            holder.ivContribution.setImageDrawable(context.getResources().getDrawable(R.drawable.contribution_second));
            holder.tvName.setTextColor(context.getResources().getColor(R.color.orange_ffdd00));
            holder.tvRankNum.setTextColor(context.getResources().getColor(R.color.orange_ffdd00));
            holder.tvRankNum.setTypeface(Typeface.defaultFromStyle(Typeface.BOLD));
            holder.tvName.setTypeface(Typeface.defaultFromStyle(Typeface.BOLD));
        }else if(position == 2){
            holder.ivContribution.setVisibility(View.VISIBLE);
            holder.ivContribution.setImageDrawable(context.getResources().getDrawable(R.drawable.contribution_third));
            holder.tvName.setTextColor(context.getResources().getColor(R.color.blue_9cd4ff));
            holder.tvRankNum.setTextColor(context.getResources().getColor(R.color.blue_9cd4ff));
            holder.tvRankNum.setTypeface(Typeface.defaultFromStyle(Typeface.BOLD));
            holder.tvName.setTypeface(Typeface.defaultFromStyle(Typeface.BOLD));

        }else{
            holder.ivContribution.setVisibility(View.INVISIBLE);
            holder.tvName.setTextColor(context.getResources().getColor(R.color.white));
            holder.tvRankNum.setTextColor(context.getResources().getColor(R.color.white));
        }
        holder.tvName.setText(receiveGift.getNickname());
        holder.tvRankNum.setText(receiveGift.getGift_value()+"");
        return convertView;
    }

    private class ViewHolder {
        ImageView ivContribution;
        TextView tvName;
        TextView tvRankNum;
    }

}
